//思路：指针移动要考虑边界问题


import javax.management.remote.rmi._RMIConnection_Stub;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        System.out.println(repeatedSubstringPattern("abac"));
    }

    public static boolean repeatedSubstringPattern(String s) {
        if (s.length() <= 1) return true;
        for (int sublen = 1; sublen <= s.length() / 2; sublen++) {
            if(s.length()%sublen!=0){
                continue;
            }
            char[] c = s.substring(0, sublen).toCharArray();
            int i=0,j=0;
            while(j<s.length()){
                if(j<s.length()-1&&s.charAt(j)==c[i]){
                    if(i==c.length-1){
                        i=0;
                        j++;
                    }else{
                        i++;j++;
                    }
                }else{
                    break;
                }
            }
            if(j==s.length()-1){
                return true;
            }

        }
        return false;
    }
}